import numpy as np
from common import get_min


def demo():
    """
    min f = -2 * x0 + 4 * x1

    -3 * x0 + x1 <= 6
    x0 + 2 * x1 >= 4
    x0 + 3 * x1 = 4
    x1 >= -3

    :return:
    """
    c = np.array([-2, 4])

    a_ub = np.array([[-3, 1], [-1, -2]])
    b_ub = np.array([6, -4])

    a_ed = np.array([[1, 3]])
    b_ed = np.array([4])

    bounds = ([None, None], [-3, None])

    return get_min(c=c, a_ub=a_ub, b_ub=b_ub, a_ed=a_ed, b_ed=b_ed, bounds=bounds)


def optimize_max():
    """
    max 10 * s + 9 * d
    0.7 * s + d <= 630
    0.5 * s + 5 / 6 * d <= 600
    s + 2 / 3 * d <= 708
    0.1 * s + 0.25 * d <= 135

    scipy.optimize.linprog只能求最小值，最大值要反向
    :return:
      1、fun：目标值(结果)
      2、x：数组，s 和 d 的对应值
    """
    c = np.array([-10, -9])

    # 不等式左侧：要小于或等于，大于或等于需要反向，等号的要特殊处理
    a_ub = np.array([[0.7, 1], [0.5, 5/6], [1, 2/3], [0.1, 0.25]])

    # 不等式右侧
    b_ub = np.array([630, 600, 708, 135])

    bounds = ([None, None], [None, None])

    return get_min(c=c, a_ub=a_ub, b_ub=b_ub, bounds=bounds)


def run():
    """

    :return:
    """
    demo_v = demo()
    max_v = optimize_max()

    info = 'demo计算结果： {}\n\n最大优化计算结果：{}'.format(demo_v, max_v)
    print(info)


if __name__ == '__main__':
    run()
